package com.itheima.controller;

import com.itheima.pojo.Dept;
import com.itheima.pojo.Emp;
import com.itheima.pojo.Result;
import com.itheima.service.DeptService;
import com.itheima.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.function.LongFunction;

@Slf4j
    @RestController
    @RequestMapping("/depts")
    public class DeptController {
        @Autowired
        private DeptService deptService;

        /**
         * 查询部门列表
         */
        @GetMapping
        public Result list() {
            List<Dept> deptList = deptService.findAll();

            return Result.success(deptList);
        }


        @DeleteMapping
        public Result delete(Integer id) {
            System.out.println("根据部门删除" + id);

            deptService.deleteById(id);
            return Result.success();
        }

        @PostMapping
        public Result add(@RequestBody Dept dept) {
            System.out.println("新增部门" + dept);
            deptService.save(dept);
            return Result.success();
        }

        @GetMapping("/{id}")
        public Result queryById(@PathVariable("id") Integer deptId) {
            System.out.println("进入到根据id的方法,deptId" + deptId);
            Dept dept = deptService.queryById(deptId);
            return Result.success(dept);
        }

        @PutMapping
        public Result update(@RequestBody Dept dept) {
            System.out.println("修改部门, dept=" + dept);
            deptService.update(dept);
            return Result.success();
        }

}
